<html>
<head>

    <script type="text/javascript" language="javascript">
        function validasi() {
            var name = document.getElementById("question").value;
            var pilA = document.getElementById("pilA").value;
            var pilB = document.getElementById("pilB").value;
            var pilC = document.getElementById("pilC").value;
            var pilD = document.getElementById("pilD").value;
            var answer = document.getElementById("answer").value;
            var target = document.getElementsByName("option");

            if (name == null || name == "") {
                err.innerHTML = "Please insert the question!";
                return false;
            }
            else if (pilA == null || pilA == "") {
                err.innerHTML = "Please insert the option A";
                return false;
            }
            else if (pilB == null || pilB == "") {
                err.innerHTML = "Please insert the option B";
                return false;
            }
            else if (pilC == null || pilC == "") {
                err.innerHTML = "Please insert the option C";
                return false;
            }
            else if (pilD == null || pilD == "") {
                err.innerHTML = "Please insert the option D";
                return false;
            }

            else if (answer == null || answer == "") {
                err.innerHTML = "Please insert the answer";
                return false;
            }
            else if (answer != pilA && answer != pilB && answer != pilC && answer != pilD) {
                err.innerHTML = "Please insert the right answer based on the option";
                return false;
            }
            else if(target[0].checked == false && target[1].checked == false)
            {
                err.innerHTML = "Please choose the answer of the target word!";
                return false;
            }
            else {
                return true;


            }


        }


    </script>
    <link href="style.css" rel="stylesheet"/>
</head>
<body>

<form id="form1" method="post" action="doEditQuePilgan.jsp" onsubmit="return validasi()">

    <table>
        <div id="popup-header">
            <h2>Edit Question's Details</h2>
        </div>
        <tr>
            <td colspan="2">Question's Type : MultipleChoice</td>

        </tr>
        <tr>

            <%

                rs = stat.executeQuery("select * from detailquestion a, detailtest b where a.detailTestID = b.detailTestID and questionID = '" + idnya + "' ");
                while (rs.next()) {
                    String testID = rs.getString("testID");
            %>

            <td><input type="hidden" name="Testid" id="Testid" value="<%=testID%>"></td>

        </tr>
        <%


            String queID = rs.getString("questionID");
            String que = rs.getString("Question");
            String pilA = rs.getString("Option_1");
            String pilB = rs.getString("Option_2");
            String pilC = rs.getString("Option_3");
            String pilD = rs.getString("Option_4");
            String answer = rs.getString("Answer");

        %>

    </table>
    <table id="word1">


        <tr>
            <td>Question</td>
            <td>:</td>
            <td><textarea name="question" id="question"><%=que%>
            </textarea></td>
            <input type="hidden" name="idque" id="idque" value="<%=queID%>">
        </tr>
        <tr>
            <td align="center">A.</td>
            <td></td>
            <td><input type="text" id="pilA" name="pilA" value="<%=pilA%>"></td>
        </tr>

        <tr>
            <td align="center">B.</td>
            <td></td>
            <td><input type="text" id="pilB" name="pilB" value="<%=pilB%>"></td>
        </tr>

        <tr>
            <td align="center">C.</td>
            <td></td>
            <td><input type="text" id="pilC" name="pilC" value="<%=pilC%>"></td>
        </tr>

        <tr>
            <td align="center">D.</td>
            <td></td>
            <td><input type="text" id="pilD" name="pilD" value="<%=pilD%>"></td>
        </tr>
        <tr>
            <td>Answer</td>
            <td>:</td>
            <td><input type="text" name="answer" id="answer" value="<%=answer%>"></td>
        </tr>
        <table>
            <tr>
                <td>Target Word</td>
                <td>:</td>
                <td>
                    <input type="radio" name="option" id="yes" value="yes"><label>Yes</label>
                    <input type="radio" name="option" id="no" value="no"><label>No</label>
                </td>


            </tr>
        </table>
        <tr id="warning">

            <td colspan="3">
                <div id="err"></div>
            </td>
        </tr>

        <tr align="right">
            <td colspan="3">
                <div class="btn-fld">
                    <button type="submit">Save</button>
                </div>

            </td>
        </tr>

        <% }
        %>
    </table>
</form>
</body>
</html>
